#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3

def parse(db, fname):
    """
    Function take 2 parameters:
        1. db file
        2. txt file
    """
    try:
        con = sqlite3.connect(db)
        con.isolation_level = "EXCLUSIVE"
        con.text_factory = str
        cur = con.cursor()
    except Exception, e:
        print e
        return
        
    try:
        text_file = open(fname, "r\n")
    except Exception, e:
        print e
        return
        
    for line in text_file.xreadlines():
        cur.execute('insert into alphabet values(?, ?, ?)', line.strip().split(' '))
    con.commit()

if __name__ == "__main__":
    import sys
    if len(sys.argv) == 3:
        parse(sys.argv[1], sys.argv[2])
    else:
        print parse.__doc__